﻿using BookManege.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManege.controller
{
    public partial class stillbookManage : Form
    {
        private StillApplication stillApplication;
        public stillbookManage()
        {
            this.stillApplication = new StillApplication();
            InitializeComponent();
        }

        private void stillbookManage_Load(object sender, EventArgs e)
        {
            GetStillApplication();
        }
        public void GetStillApplication()
        {
            dataGridView1.DataSource = stillApplication.GetAllStillApplication();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                DataGridViewRow row = dataGridView1.Rows[i];
                string state = row.Cells["处理情况"].Value.ToString();
                string result = row.Cells["处理结果"].Value.ToString();

                if (!string.IsNullOrEmpty(state))
                {
                    if (state == "0")
                    {
                        dataGridView1.Invoke((MethodInvoker)delegate { row.Cells["处理情况"].Value = "未处理"; });
                    }
                    else
                    {
                        dataGridView1.Invoke((MethodInvoker)delegate { row.Cells["处理情况"].Value = "已处理"; });
                    }

                }
                if (!string.IsNullOrEmpty(result))
                {
                    if (result == "0")
                    {
                        dataGridView1.Invoke((MethodInvoker)delegate { row.Cells["处理结果"].Value = "驳回"; });
                    }
                    else
                    {
                        dataGridView1.Invoke((MethodInvoker)delegate { row.Cells["处理结果"].Value = "同意"; });
                    }
                }

            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Columns[e.ColumnIndex].Name == "处理")
            {
                long id = Convert.ToInt64(dataGridView1.Rows[e.RowIndex].Cells["申请号"].Value.ToString());
                stillDetails stillDetails = new stillDetails(id, this);
                stillDetails.Show();
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string state = comboBox1.SelectedIndex.ToString();
            dataGridView1.DataSource= stillApplication.Serch(state,null);
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            string process = comboBox2.SelectedIndex.ToString();
            dataGridView1.DataSource = stillApplication.Serch(null, process);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            comboBox2.SelectedIndex = comboBox1.SelectedIndex = -1;
            GetStillApplication();
        }
    }
}
